package cn.tedu.boot3_4.Controller;

import cn.tedu.boot3_4.entity.Hero;
import cn.tedu.boot3_4.mapper.HeroMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class HeroController {
    @Autowired(required = false)
    HeroMapper mapper;
    @RequestMapping("/add")
    public String add(Hero hero){
        mapper.insert(hero);
        return "添加完毕";
    }
    @RequestMapping("/select")
    public String select(){
     List<Hero> list=mapper.select();
     String html="<table border=1>";
     html+="<caption>英雄列表</caption>";
     html+="<tr><th>id</th><th>姓名</th><th>类型</th><th>价格</th></tr>";
     for(Hero h:list){
         html+="<tr>";
         html+="<td>"+h.getId()+"</td>";
         html+="<td>"+h.getName()+"</td>";
         html+="<td>"+h.getType()+"</td>";
         html+="<td>"+h.getMoney()+"</td>";
         html+="</tr>";
     }
     html+="</table>";
     return html;
    }




}




